﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using YArchitech.DataModel;

namespace YArchitech.HVAC
{
	[Transaction(TransactionMode.Manual)]
	public class TestBoostLine : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Transaction transaction = null;
			Result result;
			try
			{
				if (commandData == null)
				{
					throw new System.ArgumentNullException();
				}
				Document document = commandData.Application.ActiveUIDocument.Document;
				transaction = new Transaction(document, "绘制辅助线");
				transaction.Start();
				new AuxiliaryLineOperate(commandData).DrawDiamondArc(0.0, 0.0, 9.84251968503937, 9.84251968503937, "test");
				document.Regenerate();
				transaction.Commit();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Autodesk.Revit.Exceptions.OperationCanceledException)
			{
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex)
			{
				message = ex.Message;
				result = Autodesk.Revit.UI.Result.Failed;
			}
			finally
			{
				if (transaction != null)
				{
					TransactionStatus status = transaction.GetStatus();
					if (status == 1)
					{
						transaction.Commit();
					}
					else if (status == 5)
					{
						transaction.RollBack();
					}
				}
			}
			return result;
		}
	}
}
